/**
 * yiqihao(一起好商务股份有限公司) copyright 
 */
package com.p2p.front.web.controller;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.p2p.base.annotation.LoginNeedless;
import com.p2p.base.web.controller.BaseController;

/**
 *
 * @author leiruiqi@yiqihao.com
 *
 * 2015年2月11日 上午9:04:58
 */
@LoginNeedless
@RequestMapping("/configView")
@Controller
public class ConfigViewController extends BaseController{

	private Properties jsConfigProp = new Properties(); 
	private Map<String,String> jsConfigMap = new HashMap<String,String>();
	
	@RequestMapping("/getJsConfig")
	public void getJSConfig(HttpServletResponse response){
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("success", true);
		jsonObj.put("jsConfig", jsConfigMap);
		this.returnJsonObject(response, jsonObj);
	}
	
	
	@PostConstruct
	public void initJsFront(){
		String configPath2 = System.getProperty("p2p.config_path");
		if(configPath2.startsWith("file:")){
			configPath2 = configPath2.replaceFirst("file:", "");
		}
		InputStream in;
		try {
			in = new BufferedInputStream(new FileInputStream(configPath2+"/config/jsConfig"+".properties"));
			jsConfigProp.load(in);
			for(Entry<Object,Object> entry:jsConfigProp.entrySet()){
				jsConfigMap.put(entry.getKey().toString(), entry.getValue().toString());
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
